function showDiv(cDiv,sDiv){
    cDiv.click(function(){
        if($(this).hasClass('show')){
            sDiv.hide();
            $(this).removeClass('show');
        }else{
            sDiv.show();
            $(this).addClass('show');
        }
    })
}
function picture(picData,box){
	var num = Math.floor(Math.random() * picData.length);
	//console.log(num);
	var picBox = document.getElementById(box);
	if(picBox){
		picBox.innerHTML = picData[num];
	}
}
function onTabPlay(){
    $('.playname li').click(function(){
        var type = $(this).attr('data-type'),
            a = localStorage.playtabname = $(this).attr("data-type"),
            b = localStorage.playtabvid = $(this).attr("data-vid");
        $('.play-icon span').attr('class','ikf-icon ' + type);
        $('.playlist').hide();
        $('#' + type).show();
        a && b && (Play(b, a))
    });
}
$(document).ready(function(){
    showDiv($('.play-icon'),$('.playname'));
    onTabPlay();
    var $cura = $('.ikf-playlist ul li.cur');
    if($('.ikf-playlist ul li').hasClass('cur')){
        var posi=$cura.position();
        $(".ikf-playlist").animate({scrollTop:posi.top},200);
    }
    function a(a) {
        var b = new Array();
        return b["tudou"] = "土豆", b["youku"] = "优酷", b["iqiyi"] = "爱奇艺", b["letv"] = "乐视",
        b["sohu"] = "搜狐", b["pptv"] = "聚力", b["qq"] = "腾讯", b["letvyun"] = "乐视云", b["bilibili"] = "哔哩哔哩", b["acfun"] = "A站", b["other"] = "其他", b["pv"] = "PV", b["bgm"] = "BGM", b["ed"] = "ED", b["cm"] = "CM", b["op"] = "OP", b["mad"] = "MAD", b["other"] = "其他A", b["otherB"] = "其他B", b["otherC"] = "其他C", b["otherD"] = "其他D", b["nodel"] = "未删减", b[a];
    }
    var url = window.location.href;
    if(url.indexOf('.html') !== -1 && url.indexOf('/ac/') !== -1){
        var url = 'http://www.ikanfan.com/index.php?s=home-vod-playerJson-id-' + playConfig.id
        $.getJSON(url, function(data){
            if(data.status === 1){
                var data = data.data.Data, html = '', vid, name, type, list = $('.ikf-tool .playname li');
                for (var e = 0; e < data.length; e++) {
                    vid = playConfig.pid <= data[e].playurls.length && data[e].playurls[parseInt(playConfig.pid) - 1][1];
                    if(vid){
                        type = data[e].playname;
                        name = a(type);
                        for(var i = 0; i < list.length; i++){
                            if(name === list.eq(i).text()){
                                if(list.eq(i).hasClass('current')){
                                    html += '<li class="current" data-type="' + type + '" data-vid="' + vid + '"><span class="ikf-icon ' + type + '"></span>' + name + "</li>";
                                }else{
                                    html += '<li data-type="' + type + '" data-vid="' + vid + '"><span class="ikf-icon ' + type + '"></span>' + name + "</li>";
                                }
                            }
                        }
                    }
                }
                $('.playname').html('');
                $(".playname").html(html);
                $('.play-icon span').attr('class','ikf-icon ' + $('.playname .current').attr('data-type'));
                onTabPlay();
                $('.playname li .other').trigger('click');
            }
        });
    }
    //显示简介
    $('.ikf-des .ikf-title').click(function(){
        $('.ikf-info').show();
    })
    $('.ikf-info .ikf-title i').click(function(){
        $('.ikf-info').hide();
    })
    //获取播放列表的宽
    // var len = $('.ikf-playlist .playlist').length;
    // for(var i = 0; i< len; i++){
    //     var playlist = $('.ikf-playlist .playlist').eq(i).find('li');
    //     $('.ikf-playlist .playlist').eq(i).width(playlist.width() * playlist.length + playlist.length);
    // }
    //点击切换播放源
    //点击查看全部播放列表
    // $('.ikf-title .all').click(function(){
    //     $('.ikf-playlisttan').show();
    //     $('.ikf-playlisttan .playlist').html($('.ikf-playlist .playlist').html());
    // })
    // $('.ikf-playlisttan').on('click', '.ikf-title i', function(){
    //     $('.ikf-playlisttan').hide();
    //     $('.ikf-playlisttan .playlist').html('');
    // })
    //获取角色的宽
    var actorlist = $('.ikf-actor ul li');
    $('.ikf-actor ul').width(actorlist.width() * actorlist.length + actorlist.length);
    //获取相关动漫的宽
    var itemlist = $('.like a');
    $('.like .item').width(itemlist.width() * itemlist.length + 3 + itemlist.length);
    //获取相关动漫的宽
    var itemlist = $('.hot a');
    $('.hot .item').width(itemlist.width() * itemlist.length + 5 + itemlist.length);
    //点击显示分享弹层
    $('.ikf-tool .share').click(function(){
        $('.ikf-share').show();
    })
    $('.ikf-share span i').click(function(){
        $('.ikf-share').hide();
    })
    $('.arrow').click(function(){
        if($(this).hasClass('active')){
            $('.pTxt').attr('style','');
            $(this).removeClass('active');
        }else{
            $('.pTxt').height('auto').css({'white-space':'normal','padding-right': '.2rem'});
            $(this).addClass('active');
        }
    });
    //图片懒加载
    if($(".item").eq(0).length){
        $("img.lazy").lazyload({
            effect : "fadeIn",
            container: $(".item").eq(0)
        });
    }
    if($(".item").eq(1).length){
        $("img.lazy").lazyload({
            effect : "fadeIn",
            container: $(".item").eq(1)
        });
    }
    if($(".clearfix").length){
        $("img.lazy").lazyload({
            effect : "fadeIn",
            container: $(".clearfix")
        });
    }
    $("img.lazy").lazyload({
         effect : "fadeIn"
    });
    $('.ikf-nav .back').click(function(){
        window.history.go(-1);
    })
    $(".search")[0] && $(".search").click(function(e) {
        if ($(".ikf-searchPop").css("display") == "none") {
            $("html,body").css({
                "overflow-y": "hidden"
            });
            $(".ikf-searchPop").show();
        } else {
            $("html,body").css({
                "overflow-y": "auto"
            });
            $(".ikf-searchPop").hide();
        }
    });
    $(".cancelInput").click(function() {
		$html = $(this).html();
	    $(".ikf-searchPop").hide();
		$("html,body").css({
            "overflow-y": "auto"
        });
	});
});

function start(){picH>tmpH?(tmpH+=scrollstep,tmpH>picH&&(tmpH=picH),Mar.scrollTop=tmpH,setTimeout(start,scrolltime)):(tmpH=0,Mar.appendChild(child_div[0]),Mar.scrollTop=0,setTimeout(start,stoptime))}
var Mar,child_div,picH,scrollstep,scrolltime,stoptime,tmpH;
Mar=document.getElementById("Marquee"),child_div=Mar.getElementsByTagName("div"),picH=30,scrollstep=3,scrolltime=20,stoptime=3e3,tmpH=0,Mar.innerHTML+=Mar.innerHTML,onload=function(){setTimeout(start,stoptime)};
